<?php

declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreateProjectDelayReviewWorkflowRelationTable extends AbstractMigration
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function up()
    {
        $table = $this->table('project_delay_review_workflow_relation', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '项目延期审核流关联']);
        $table->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '关系ID'])
            ->addColumn('step_category_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '环节ID'])
            ->addColumn('review_workflow_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '审批流配置ID'])
            ->addColumn('uuid', 'char', ['default' => '', 'limit' => 36, 'comment' => '全局唯一标识符'])
            ->addColumn('project_id', 'integer', ['default' => 0, 'null' => false, 'limit' => 11, 'comment' => '项目ID'])
            ->addColumn('attr_str', 'string', ['default' => '', 'null' => false, 'limit' => 256, 'comment' => '属性attr'])
            ->addColumn('review_node_config', 'json', ['null' => true, 'comment' => '审核人员配置'])
            ->addIndex(['project_id', 'step_category_id', 'attr_str'], ['type' => 'unique', 'name' => 'idx_unique_step_category_workflow_attr'])
        ;
        $table->create();
    }

    public function down()
    {
        $this->table('project_delay_review_workflow_relation')->drop()->save();
    }
}
